package cn.bjc._04_sync;


import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

public class Producer {
    public static void main(String[] args) throws Exception {
        
        //1.实例化生产者
        DefaultMQProducer producer = new DefaultMQProducer("sync_producer_group");
        
        //2.设置地址
        producer.setNamesrvAddr("localhost:9876");
        
        //3.启动生产者
        //此处抛大异常
        producer.start();
        
        //4.设置消息
        //参数一:"主题",参数二:"标签",参数三:"数据"(数据要转成byte,并设置编码)
        Message message = new Message("sync", "java", "我爱源码".getBytes(StandardCharsets.UTF_8));
        SendResult send = producer.send(message);
        System.out.println(send);

        //5.关闭生产者
        producer.shutdown();
        

    }
}
